﻿namespace 三
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Student student1 = new Student("张三", 1001);
            student1.AddGrade("数学", 85.5);
            student1.AddGrade("英语", 92.0);
            student1.AddGrade("物理", 78.5);
            student1.AddGrade("化学", 88.0);

            Student student2 = new Student("李四", 1002);
            student2.AddGrade("数学", 95.0);
            student2.AddGrade("英语", 87.5);
            student2.AddGrade("物理", 91.0);
            student2.AddGrade("化学", 84.5);

            student1.GP = GradeReport.GradeReportOrderByTerm;
            student2.GP = GradeReport.GradeReportOrderByTerm;

            student1.PrintGrade();
            student2.PrintGrade();
        }
        public delegate bool GradePrint(Student s);

        public class Student
        {
            public string name;
            public int grade;
            public Dictionary<string, double> Grades { get; set; }
            public Student(string name, int grade)
            {
                this.name = name;
                this.grade = grade;
                Grades = new Dictionary<string, double>();
            }
            public void AddGrade(string subject, double score)
            {
                Grades[subject] = score;
            }
            public GradePrint GP { set; get; }
            public void PrintGrade()
            {
                if (GP != null)
                {
                    GP(this);
                }
            }

        }
        public class GradeReport
        {
            public static bool GradeReportOrderByTerm(Student s)
            {
                Console.WriteLine($"--- {s.name}的成绩单 ---");
                foreach (var grade in s.Grades)
                {
                    Console.WriteLine($"{grade.Key}: {grade.Value}");
                }
                return true;
            }
        }
    }
}
